home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10034 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: EU.net!sun4nl!xs4all!falstaff
  2. From: falstaff@xs4all.nl (Falstaff)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: integer and real numbers in C/C++
  5. Date: 14 Mar 1996 20:03:36 GMT
  6. Organization: XS4ALL, networking for the masses
  7. Message-ID: <4i9u2o$1a9@news.xs4all.nl>
  8. References: <31477D44.782@macon.wm.slb.com>
  9. NNTP-Posting-Host: xs1.xs4all.nl
  10. X-Newsreader: NN version 6.5.0 #666 (NOV)
  11.  
  12. Laurent Darton <darton@macon.wm.slb.com> writes:
  13.  
  14. >Hi every all,
  15. >According to IEEE 754, I can use integer coded on 24 bits (3 Bytes), 
  16. >integer coded on 48 bits (6 Bytes) and on 64 bits...
  17.  
  18. IEEE754 is a *floating point* standard.
  19.  
  20. >How can I declare those values in C... I suppose I need to create new 
  21. >data structures to do that.. But I don't know how to do ...
  22. > My compiler (MSVC 1.52) says :
  23. >long=4 Bytes
  24.  
  25. float is 4 bytes
  26.  
  27. >double =8 Bytes
  28. >long double =10 Bytes
  29.  
  30. >My problem is 
  31. >    - I don't want to use a long (4 Bytes) to code 3 bytes (but it     
  32. >works fine..)
  33. >    - I cannot code an integer with 8 Bytes  (but only a double..)
  34.  
  35. What's the problem in using a long for a 24-bit integer?  Your computer
  36. would be able to handle 32-bit numbers faster than 24-bit ones.
  37.  
  38. Of course, if you're storing data in binary form in files, you could
  39. chop off the unwanted bits by
  40.  
  41.    fputc((Num>>16)&0xff,outFile);
  42.    fputc((Num>>8)&0xff,outFile);
  43.    fputc(Num&0xff,outFile);
  44.  
  45. (those ANDs are there only for clarity, not really needed as the
  46. implicit conversions involved will simply throw away higher-order
  47. bits anyway).
  48.  
  49. Frank
  50. --
  51. The famous GIICM now on line:  http://www.xs4all.nl/~falstaff/GIICM.html
  52. ------------------------------------------------------------------------
  53. Frank A. Vorstenbosch        +31-(70)-355 5241        falstaff@xs4all.nl
  54.